package com.share.web.util;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;


public class ListenerOnlineEmp implements HttpSessionListener,
		HttpSessionAttributeListener {
	
	private int totalOnlineEmp ;

	public void sessionCreated(HttpSessionEvent sess) {
	}
	public void sessionDestroyed(HttpSessionEvent sess) {
	}
	
	public void attributeAdded(HttpSessionBindingEvent session) {
		/**
		 * 监听员工是否登录
		 */
		if(session.getName().equals("employee")) {
			totalOnlineEmp++ ;
			session.getSession().getServletContext().setAttribute("totalOnlineEmp", totalOnlineEmp) ;
		}
	}
	
	/**
	 * 用户注销退出之后。删除empCount范围的内容
	 */
	public void attributeRemoved(HttpSessionBindingEvent session) {
		if(session.getName().equals("employee")) {
			totalOnlineEmp = ((Integer)session.getSession().getServletContext().getAttribute("totalOnlineEmp")) -1 ;
			session.getSession().getServletContext().setAttribute("totalOnlineEmp", totalOnlineEmp) ;
		}
	}

	public void attributeReplaced(HttpSessionBindingEvent sess) {
		
	}


}
